﻿using Sidvall.Tasks;

namespace Sidvall.UI.Dialogs
{
    public sealed class ProgressDialogContext
    {
        #region Public Members

        public string Title { get; set; }
        public double SpeedFactor { get; set; }
        public string SpeedFormat { get; set; }
        public string SpeedUnit { get; set; }
        public string TimeFormat { get; set; }
        public bool CanCancel { get; set; }
        public bool CloseWhenFinished { get; set; }
        public bool CloseWhenFaulted { get; set; }
        public bool ShowProgress { get; set; }
        public bool ShowSpeed { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "ShowTime")]
        public bool ShowTime { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "ShowTime")]
        public bool ShowTimeLeft { get; set; }
        public Sidvall.Tasks.TaskStatus Status { get; set; }
        public System.Exception Exception { get; set; }
        public bool ExecuteTasksAsOne { get; set; }

        #region Tasks

        private MonitoredTaskCollection _Tasks;
        public MonitoredTaskCollection Tasks
        {
            get
            {
                if (_Tasks == null)
                    _Tasks = new MonitoredTaskCollection();
                return _Tasks;
            }
        }

        #endregion

        #region NewProgressDialogContext

        public static ProgressDialogContext NewProgressDialogContext(string title)
        {
            return new ProgressDialogContext()
            {
                CanCancel = true,
                Title = title,
                CloseWhenFaulted = false,
                CloseWhenFinished = true,
                SpeedFactor = 0,
                SpeedFormat = null,
                SpeedUnit = null,
                ShowProgress = true,
                ShowSpeed = false,
                ShowTime = true,
                ShowTimeLeft = true,
                TimeFormat = @"hh\:mm\:ss",
            };
        }

        #endregion
        #region NewFileProgressDialogContext

        public static ProgressDialogContext NewFileProgressDialogContext(string title)
        {
            return new ProgressDialogContext()
            {
                CanCancel = true,
                Title = title,
                CloseWhenFaulted = false,
                CloseWhenFinished = true,
                SpeedFactor = 1d / 1024,
                SpeedFormat = "### ### ### ### ### ###",
                SpeedUnit = "kB/s",
                ShowProgress = true,
                ShowSpeed = true,
                ShowTime = true,
                ShowTimeLeft = true,
                TimeFormat = @"hh\:mm\:ss",
            };
        }

        #endregion

        #endregion
        #region Constructor

        public ProgressDialogContext()
        {
        }

        #endregion
    }
}
